/*
 * Title:        CloudScheduler Toolkit
 * Description:  a Toolkit for Modeling and Simulation of Job Scheduling and Resource Provisioning in Cloud System
 * Licence:      GPL - http://www.gnu.org/copyleft/gpl.html
 * Author:       Fuhui Wu
 *
 * Copyright (c) 2013-2014, The National University of Defense Technology, China
 */

package org.nudt.jCloud.example.resourceStealing2;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Evaluation {
	public static void main(String arg[]){
		analysis("Avg_Threshold_Stealing", "UserBroker3");
	}
	
	public static void analysis(String simName, String userBroker){
		File taskFile = new File("Log/"+simName+"/"+userBroker+"_Frwk");
		List<Double> timeStampSet = new ArrayList<Double>();
		List<Integer> totalSlotNumSet = new ArrayList<Integer>();
		try {
			if(taskFile.exists()==false){
				throw new FileNotFoundException("no such task log file.");
			}else{
				BufferedReader br = new BufferedReader(new FileReader(taskFile));
				String line = br.readLine();
				while(line != null){
					String[] fields = line.split(";");
					timeStampSet.add(Double.parseDouble(fields[0]));
					totalSlotNumSet.add(Integer.parseInt(fields[7]));
					line = br.readLine();
				}
				br.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		double cumT = 0;
		int cumTotalNum = 0;
		int splitSize = totalSlotNumSet.size()/50;
		int count = 0;
		for(int i=0; i<timeStampSet.size(); ++i){
			cumT += timeStampSet.get(i);
			cumTotalNum += totalSlotNumSet.get(i);
			count ++;
			if(count == splitSize){
				System.out.println(cumT/splitSize+"\t"+cumTotalNum/splitSize);
				cumT = 0;
				cumTotalNum = 0;
				count = 0;
			}
		}
	}

}
